package com.shu.boomFilter;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;

/**
 * @author ssm
 * @version V1.0
 * @description: 布隆过滤器
 * @date 2019/3/1 18:54
 */

public class Test {
  public static void main(String... args) {
    /**
     * 创建一个插入对象为一亿，误报率为0.01%的布隆过滤器
     */
    BloomFilter<CharSequence> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.forName("utf-8")), 10, 0.9);
    bloomFilter.put("121");
    bloomFilter.put("122");
    bloomFilter.put("123");

    Runnable runnable = () -> {
      boolean mightContain = bloomFilter.mightContain("1");
      if (!mightContain) {
        System.out.println(mightContain);
      }
    };

    for (int i = 0; i < 1000; i++) {
      runnable.run();
    }

  }
}
